{% extends "base.html" %}
{% block base %}

<nav class="navbar navbar-inverse navbar-fixed-top">
    <div class="container-fluid">
        <div class="navbar-header">
            <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar"
                    aria-expanded="false" aria-controls="navbar">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" href="#">陈勇志的接口测试平台</a>
        </div>
        <div id="navbar" class="navbar-collapse collapse">
            <ul class="nav navbar-nav navbar-right">
                <li><a href="#">设置</a></li>
                <li><a href="/logout/">退出</a></li>
            </ul>
            <form class="navbar-form navbar-right">
                <input type="text" class="form-control" placeholder="搜索...">
            </form>
        </div>
    </div>
</nav>

<div class="container-fluid">
    <div class="row">
        <div class="col-sm-3 col-md-2 sidebar">
            <ul class="nav nav-sidebar">
                <li><a href="/project/"><i class="glyphicon glyphicon-th-large">&nbsp;</i>项目管理 <span class="sr-only">(current)</span></a>
                </li>
                <li><a href="/module/"><i class="glyphicon glyphicon-th">&nbsp;</i>模块管理</a></li>
            </ul>
            <ul class="nav nav-sidebar">
                <li><a href="/case_manage/">用例管理</a></li>
                <li class="active"><a href="/task_manage/">任务管理</a></li>
            </ul>
            <ul class="nav nav-sidebar">
                <li><a href="">mock server</a></li>
                <li><a href="">测试工具</a></li>
                <li><a href="">更多工具</a></li>
            </ul>
        </div>
        <div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">

            {% if type == "task_manage" %}
            <!--模块列表-->
            <h4 class="sub-header">任务列表
                <button type="button" onclick="location.href='/task_manage/task_create/'" class="btn btn-sm btn-primary"
                        style="float:right">新建
                </button>
            </h4>
            <div class="table-responsive">
                <table class="table table-striped">
                    <thead>
                    <tr>
                        <th>id</th>
                        <th>任务名称</th>
                        <th>任务状态</th>
                        <th>创建日期</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    {% for each_task in tasks %}
                    <tr>
                        <td>{{ each_task.id }}</td>
                        <td>{{ each_task.name}}</td>
                        {% if each_task.status == 0 %}
                        <td>未执行</td>
                        {% endif %}

                        {% if each_task.status == 1 %}
                        <td>进行中</td>
                        {% endif %}

                        {% if each_task.status == 2 %}
                        <td>已完成</td>
                        {% endif %}

                        <td>{{ each_task.create_time | date:"Y-m-d H:i:s" }}</td>
                        <td>
                            <a href="#" onclick="RunTask('{{ each_task.id }}')" style="margin-right:8px"><span
                                    class="glyphicon glyphicon-play">运行</span></a>
                            <!--编辑按钮-->
                            <a href="/task_manage/task_edit/{{ each_task.id }}/" style="margin-right:8px">
                                <i class="glyphicon glyphicon-pencil">编辑</i>
                            </a>
                            <!--删除按钮-->
                            <a href="/task_manage/task_del/{{ each_task.id }}/" style="margin-right:8px">
                                <i style="padding-left:5px;" class="glyphicon glyphicon-trash">删除</i>
                            </a>
                            <a href="/task_manage/task_report/{{ each_task.id }}/" style="margin-right:8px"><span
                                    class="glyphicon glyphicon-list-alt">报告</span></a>
                        </td>
                    </tr>
                    {% endfor %}
                    </tbody>
                </table>
            </div>
            <div>
            </div>
            {% endif %}

            {% if type == "task_create" %}

            {% block task_create %}
            <!--其他页面可以继承 task_manage.html -->
            {% endblock %}

            {% endif %}


            {% if type == "task_edit" %}
            {% block task_edit %}

            <!----其他页面可以继承 task_manage.html  -->
            {% endblock %}
            {% endif %}

            {% if type == "task_report" %}
            {% block task_report %}

            {% endblock %}
            {% endif %}

        </div>
    </div>

</div>
<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>

<link href="http://cdn.bootcss.com/zTree.v3/3.5.23/css/zTreeStyle/zTreeStyle.css" rel="stylesheet">
<script src="http://cdn.bootcss.com/zTree.v3/3.5.23/js/jquery.ztree.all.js"></script>
<script type="text/javascript">

    function RunTask(task_id){
        window.alert("运行任务的ID" + task_id);
        //获取当前时间
        var timestamp = (new Date()).valueOf();
        console.log(timestamp);

        $.post('/task_manage/task_run/',
            {
                task_id:task_id,
                my_time:timestamp,
            },
            function(resp){

            if(resp.status == 10200){
                window.alert(timestamp)
                window.location.reload()
                }
            else {
                    window.alert(resp.msg)
                }
            }
        )
    }






</script>
{% endblock %}
